package com.example.droolstest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.droolstest.dao.BusinessRuleTempDao;
import com.example.droolstest.entity.BusinessRuleTemp;
import com.example.droolstest.exception.ServiceException;
import com.example.droolstest.service.BusinessRuleTempService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class BusinessRuleTempServiceImpl extends ServiceImpl<BusinessRuleTempDao, BusinessRuleTemp> implements BusinessRuleTempService {

    @Override
    public void add(BusinessRuleTemp businessType) {
        if(StringUtils.isBlank(businessType.getName())){
            throw new ServiceException("业务类型名称不能为空");
        }
        BusinessRuleTemp one = this.getOne(
                new QueryWrapper<BusinessRuleTemp>()
                        .eq(BusinessRuleTemp.COL_NAME, businessType.getName())
        );
        if(one != null){
            throw new ServiceException("业务类型名称不能重复");
        }
        this.save(businessType);
    }
}
